var mongoose = require('mongoose')
var Comment = mongoose.model('Comment')

// comment
exports.save = function* (next) {
  var _comment = this.request.body.comment
  if(_comment.from == _comment.tid){
    delete _comment.cid
  }
  var artId = _comment.article

  if (_comment.cid) {
    var comment = yield Comment.findById({_id:_comment.cid})
    var reply = {
      from: _comment.from,
      to: _comment.tid,
      content: _comment.content
    }

    comment.reply.push(reply)

    yield comment.save()
    this.body = {success:1}
  }
  else {
    var comment = new Comment({
      article: _comment.article,
      from: _comment.from,
      content: _comment.content
    })

    yield comment.save()
    this.body = {success:1}
  }
}